package hauwei.exam416;

import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class MinNum {

    static int min=Integer.MAX_VALUE;
    public static void main(String[] args) {
        System.out.println(getMin());
    }
    public static int getMin(){
        Scanner scanner=new Scanner(System.in);
        int lines=scanner.nextInt();
        int bits=scanner.nextInt();
        scanner.nextLine();
        int[][]numbers=new int[lines][bits];
        HashMap<Integer, List<Integer>>map=new HashMap<>();
        for(int i=0;i<lines;i++){
            for (int j=0;j<bits;j++){
                numbers[i][j]=scanner.nextInt();
            }
        }
        int[]bitAnd=new int[bits];
        scanner.close();
        dfs(0,0,new int[bits],numbers);
        return min=min==Integer.MAX_VALUE?-1:min;
    }
    public static void dfs(int index,int sum,int []bits,int[][]numbers){
        if(sum>min){
            return;
        }
        int zeroI=zeroIndex(bits);
        if(zeroI==-1){//如果满了
            min=Math.min(min, sum);
            return;
        }
        if(index==numbers.length){
            return;
        }

        int[]selected=numbers[index];


        //不选这一行
        dfs(index+1, sum, bits, numbers);

        //选这一行
        for (int i=0;i<bits.length;i++){
            bits[i]+=selected[i];
        }
        dfs(index+1,sum+1,bits,numbers);
        for (int i=0;i<bits.length;i++){
            bits[i]-=selected[i];
        }

    }
    public static int zeroIndex(int[]bits){
        for (int i=0;i<bits.length;i++){
            if(bits[i]==0){
                return i;
            }
        }
        return -1;
    }
}
